Socket
Socket
Sign inDemoInstall

mitt

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mitt

Tiny 200b functional Event Emitter / pubsub.


Version published
Maintainers
1
Created

What is mitt?

The mitt npm package is a tiny, functional event emitter or pub/sub library that provides a way to emit and listen for events in JavaScript applications. It is designed to be simple, small, and fast, making it suitable for use in both the browser and Node.js environments.

What are mitt's main functionalities?

Event Emission

Emitting events with optional data. Listeners can subscribe to these events and react accordingly.

{"const mitt = require('mitt');\nconst emitter = mitt();\nemitter.emit('myEvent', { some: 'data' });"}

Event Listening

Subscribing to events. This allows functions to listen for specific events and execute code when those events are emitted.

{"const mitt = require('mitt');\nconst emitter = mitt();\nemitter.on('myEvent', (data) => {\n  console.log('Event received with data:', data);\n});"}

Event Unlistening

Removing event listeners. This provides a way to unsubscribe from events when a listener is no longer needed or the context changes.

{"const mitt = require('mitt');\nconst emitter = mitt();\nconst handler = (data) => {\n  console.log('Event received with data:', data);\n};\nemitter.on('myEvent', handler);\nemitter.off('myEvent', handler);"}

All Events Listening

Listening to all events. This special event type allows a listener to react to all events emitted by the emitter.

{"const mitt = require('mitt');\nconst emitter = mitt();\nemitter.on('*', (type, event) => {\n  console.log(`Type: ${type}, Event:`, event);\n});"}

Other packages similar to mitt

Keywords

FAQs

Package last updated on 04 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc